import 'package:dio/dio.dart';
import 'package:flutter_base_app/config/i18n/i18n.dart';
import 'package:flutter_base_app/config/i18n/i18n_key.dart';

class HttpError {
  static String getError(e) {
    // return I18nKey.networkError.trx;
    if (e is DioException) {
      //dio错误
      if (e.type == DioExceptionType.connectionTimeout) {
        return "Connection timed out";
      } else if (e.type == DioExceptionType.sendTimeout) {
        return "Request timeout";
      } else if (e.type == DioExceptionType.receiveTimeout) {
        return "Response timeout";
      } else if (e.type == DioExceptionType.badResponse) {
        return "Exception occurred";
      } else if (e.type == DioExceptionType.cancel) {
        return "Request cancellation";
      } else if (e.type == DioExceptionType.badCertificate) {
        return "Certificate error";
      } else if (e.type == DioExceptionType.connectionError) {
        return "Connection error";
      } else {
        return "Unknown error";
      }
    } else {
      return "Data parsing error";
      //json解析错误
    }
  }
}
